<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>审批结果查看</title>
</head>
<body>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <!--模糊查询表单-->
        <form class="layui-form layui-form-pane" >
            <legend>模糊信息查询</legend>
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">员工ID</label>
                        <div class="layui-input-inline">
                            <input lay-filter="employeeID" type="text" name="employeeID" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-inline">
                            <input lay-filter="people" type="text" name="people" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">申请类型</label>
                        <div class="layui-input-inline">
                            <input lay-filter="applyType" type="text" name="applyType" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">所属部门</label>
                        <div class="layui-input-inline">
                            <input lay-filter="department" type="text" name="department" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                    </div>
                </div>
            </div>
        </form>
        <!--数据表格-->
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <!--表格中的删除按钮-->
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>
    </div>
</div>

<script>
    layui.use(['form', 'table','miniPage','element'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage;

        function getUrlParam(url,parm) {
            var reg = new RegExp("(^|&)" + parm + "=([^&]*)(&|$)");
            /*表示找对应的?(？号后面跟的是参数)*/
            var r = url.substr(url.indexOf("\?") + 1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
        var id = getUrlParam(location.href,"id");
        /*传送请求id*/
        $.ajax({
            url:"/agreeApply",
            data:{
                id:id
            },
            success:function (data) {
                if(data != null){
                    console.log("cg")
                }
            }
        });

        /*数据表格*/
        table.render({
            elem: '#currentTableId',
            url: '/showOprOkData?id='+id,
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'cwbPId', width: 60, title: 'ID', sort: true},
                {field: 'cwbPEmployeeid', width: 120, title: '员工ID', sort: true},
                {field: 'cwbPApplytype', width: 100, title: '申请类型'},
                {field: 'cwbPApplyreason', width: 140, title: '申请理由'},
                {field: 'cwbPApplypeoson', title: '申请人', minWidth: 80},
                {field: 'cwbPDepartment', width: 80, title: '所属部门', sort: true},
                {field: 'cwbPMoney', width: 80, title: '申请金额', sort: true},
                {field: 'cwbPBill', width: 80, title: '发票'},
                {field: 'cwbPStatus', width: 100, title: '审批状态'},
                {field: 'cwbPApplydate', width: 135, title: '申请日期', sort: true},
                {field: 'cwbPLeader', width: 100, title: '直系领导'},
                {field: 'cwbPApproverdate', width: 100, title: '审批日期'},
                {field: 'cwbPOprpeoson', width: 100, title: '经办人'},
                {field: 'cwbPApproverpeoson', width: 100, title: '审批人'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [6, 12, 18, 24, 30],
            limit: 6,
            page: true,
            skin: 'line'
        });

        /*条件查询，表格重载数据*/
        form.on('submit(data-search-btn)',function (data) {
            var result = JSON.stringify(data.field);
            table.reload('currentTableId',{
                page:{
                    curr:1
                },
                where:{
                    condition:result   /*传输的查询条件*/
                },
                url:"/showApplyedByCondition",
                method:"post"
            });
            return false;
        });

        /**
         * toolbar事件监听
         *
         *   employeeid:data.cwbPEmployeeid,
         applytype:data.cwbPApplytype,
         reason:data.cwbPApplyreason,
         people:data.cwbPApplypeoson,
         department:data.cwbPDepartment,
         money:data.cwbPMoney,
         bill:data.cwbPBill,
         status:data.cwbPStatus,
         date:data.cwbPApplydate,
         leader:data.cwbPLeader
         */

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('确定要删除这条申请记录嘛？', function (index) {
                    $.ajax({url:"/delete",
                        dateType:"json",
                        data:{
                            id:data.cwbPId
                        }
                    });
                    /*在页面删除(没写逻辑的时候是假删除)*/
                    obj.del();
                    layer.close(index);
                });
            }
        });

    });
</script>

</body>
</html>